package 设计mos.CommandPattern;

/**
 * @作者：xie
 * @时间：2022/10/13 14:48
 */
public class mian {
    public static void main(String[] args) {
        Tv tv = new Tv();
        Command onCommand = new OnCommand(tv);
        Command offCommand = new OffCommand(tv);

        Invoker invoker = new Invoker();
        invoker.setCommand(onCommand);
        invoker.call();
        System.out.println("===================");

        invoker.setCommand(offCommand);
        invoker.call();
    }
}

class Invoker{
    private Command command;

    public void setCommand(Command command){
        this.command=command;
    }

    public void call(){
        command.Execute();
    }
}

interface Command{
    public void Execute();
}

class OnCommand implements Command{

    private Tv tv;
    public OnCommand(Tv tv) {
        this.tv=tv;
    }
    @Override
    public void Execute() {
        tv.OnAction();
    }
}
class OffCommand implements Command{
    private Tv tv;

    public OffCommand(Tv tv) {
        this.tv=tv;
    }
    @Override
    public void Execute() {
        tv.OffAction();
    }
}

class Tv{
    public void OnAction(){
        System.out.println("kj");
    }

    public void OffAction(){
        System.out.println("gj");
    }
}
